package com.shiwenping.reply.tools;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.shiwenping.reply.service.ToastService;

import ezy.assist.compat.SettingsCompat;

/**
 * @author shiwenping
 * @date 17-11-8 上午10:49
 */

public class Tools {
    public static void toastShow(Context context, boolean isShow) {
        Intent floatWinIntent = new Intent(context, ToastService.class);
        if (isShow) {
            //开始显示到屏幕
            if (SettingsCompat.canDrawOverlays(context)) {
                Intent intent = new Intent(ToastService.TOAST_OPEN_ACTION);
                context.sendBroadcast(intent);
                context.startService(floatWinIntent);
            } else {
                Toast.makeText(context, "没有权限!", Toast.LENGTH_SHORT).show();
                SettingsCompat.manageDrawOverlays(context);
                SettingsCompat.manageWriteSettings(context);
            }
        } else {
            Intent intent = new Intent(ToastService.TOAST_STOP_ACTION);
            context.sendBroadcast(intent);
            context.stopService(floatWinIntent);
        }
    }
}
